/*
FeedParser
Copyright (c) 2005, Naoya Ikeda
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are 
permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice, this list 
  of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright notice, this list
  of conditions and the following disclaimer in the documentation and/or other materials 
  provided with the distribution.

- Neither the name of the Cyber World 2000 nor the names of its contributors may be used to 
  endorse or promote products derived from this software without specific prior written 
  permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &AS IS& AND ANY EXPRESS 
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

using System;
using System.Collections;

namespace Cworld2000.Xml
{
    /// <summary>
    ///   A collection that stores <see cref='FeedEnclosure'/> objects.
    /// </summary>
    public class FeedEnclosureCollection : CollectionBase
    {

        /// <summary>
        ///   Initializes a new instance of <see cref='FeedEnclosureCollection'/>.
        /// </summary>
        public FeedEnclosureCollection()
        {
        }

        /// <summary>
        ///   Initializes a new instance of <see cref='FeedEnclosureCollection'/> based on another <see cref='FeedEnclosureCollection'/>.
        /// </summary>
        /// <param name='val'>
        ///   A <see cref='FeedEnclosureCollection'/> from which the contents are copied
        /// </param>
        public FeedEnclosureCollection(FeedEnclosureCollection val)
        {
            this.AddRange(val);
        }

        /// <summary>
        ///   Initializes a new instance of <see cref='FeedEnclosureCollection'/> containing any array of <see cref='FeedEnclosure'/> objects.
        /// </summary>
        /// <param name='val'>
        ///       A array of <see cref='FeedEnclosure'/> objects with which to intialize the collection
        /// </param>
        public FeedEnclosureCollection(FeedEnclosure[] val)
        {
            this.AddRange(val);
        }

        /// <summary>
        ///   Represents the entry at the specified index of the <see cref='FeedEnclosure'/>.
        /// </summary>
        /// <param name='index'>The zero-based index of the entry to locate in the collection.</param>
        /// <value>The entry at the specified index of the collection.</value>
        /// <exception cref='ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
        public FeedEnclosure this[int index]
        {
            get
            {
                return ((FeedEnclosure)(List[index]));
            }
            set
            {
                List[index] = value;
            }
        }

        /// <summary>
        ///   Adds a <see cref='FeedEnclosure'/> with the specified value to the 
        ///   <see cref='FeedEnclosureCollection'/>.
        /// </summary>
        /// <param name='val'>The <see cref='FeedEnclosure'/> to add.</param>
        /// <returns>The index at which the new element was inserted.</returns>
        /// <seealso cref='FeedEnclosureCollection.AddRange(Cworld2000.Xml.FeedEnclosure[])'/>
        public int Add(FeedEnclosure val)
        {
            return List.Add(val);
        }

        /// <summary>
        ///   Copies the elements of an array to the end of the <see cref='FeedEnclosureCollection'/>.
        /// </summary>
        /// <param name='val'>
        ///    An array of type <see cref='FeedEnclosure'/> containing the objects to add to the collection.
        /// </param>
        /// <seealso cref='FeedEnclosureCollection.Add'/>
        public void AddRange(FeedEnclosure[] val)
        {
            for (int i = 0; i < val.Length; i++)
            {
                this.Add(val[i]);
            }
        }

        /// <summary>
        ///   Adds the contents of another <see cref='FeedEnclosureCollection'/> to the end of the collection.
        /// </summary>
        /// <param name='val'>
        ///    A <see cref='FeedEnclosureCollection'/> containing the objects to add to the collection.
        /// </param>
        /// <seealso cref='FeedEnclosureCollection.Add'/>
        public void AddRange(FeedEnclosureCollection val)
        {
            for (int i = 0; i < val.Count; i++)
            {
                this.Add(val[i]);
            }
        }

        /// <summary>
        ///   Gets a value indicating whether the 
        ///    <see cref='FeedEnclosureCollection'/> contains the specified <see cref='FeedEnclosure'/>.
        /// </summary>
        /// <param name='val'>The <see cref='FeedEnclosure'/> to locate.</param>
        /// <returns>
        /// <see langword='true'/> if the <see cref='FeedEnclosure'/> is contained in the collection; 
        ///   otherwise, <see langword='false'/>.
        /// </returns>
        /// <seealso cref='FeedEnclosureCollection.IndexOf'/>
        public bool Contains(FeedEnclosure val)
        {
            return List.Contains(val);
        }

        /// <summary>
        ///   Copies the <see cref='FeedEnclosureCollection'/> values to a one-dimensional <see cref='Array'/> instance at the 
        ///    specified index.
        /// </summary>
        /// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='FeedEnclosureCollection'/>.</param>
        /// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
        /// <exception cref='ArgumentException'>
        ///   <para><paramref name='array'/> is multidimensional.</para>
        ///   <para>-or-</para>
        ///   <para>The number of elements in the <see cref='FeedEnclosureCollection'/> is greater than
        ///         the available space between <paramref name='arrayIndex'/> and the end of
        ///         <paramref name='array'/>.</para>
        /// </exception>
        /// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
        /// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
        /// <seealso cref='Array'/>
        public void CopyTo(FeedEnclosure[] array, int index)
        {
            List.CopyTo(array, index);
        }

        /// <summary>
        ///    Returns the index of a <see cref='FeedEnclosure'/> in 
        ///       the <see cref='FeedEnclosureCollection'/>.
        /// </summary>
        /// <param name='val'>The <see cref='FeedEnclosure'/> to locate.</param>
        /// <returns>
        ///   The index of the <see cref='FeedEnclosure'/> of <paramref name='val'/> in the 
        ///   <see cref='FeedEnclosureCollection'/>, if found; otherwise, -1.
        /// </returns>
        /// <seealso cref='FeedEnclosureCollection.Contains'/>
        public int IndexOf(FeedEnclosure val)
        {
            return List.IndexOf(val);
        }

        /// <summary>
        ///   Inserts a <see cref='FeedEnclosure'/> into the <see cref='FeedEnclosureCollection'/> at the specified index.
        /// </summary>
        /// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param>
        /// <param name='val'>The <see cref='FeedEnclosure'/> to insert.</param>
        /// <seealso cref='FeedEnclosureCollection.Add'/>
        public void Insert(int index, FeedEnclosure val)
        {
            List.Insert(index, val);
        }

        /// <summary>
        ///  Returns an enumerator that can iterate through the <see cref='FeedEnclosureCollection'/>.
        /// </summary>
        /// <seealso cref='IEnumerator'/>
        public new FeedEnclosureEnumerator GetEnumerator()
        {
            return new FeedEnclosureEnumerator(this);
        }

        /// <summary>
        ///   Removes a specific <see cref='FeedEnclosure'/> from the <see cref='FeedEnclosureCollection'/>.
        /// </summary>
        /// <param name='val'>The <see cref='FeedEnclosure'/> to remove from the <see cref='FeedEnclosureCollection'/>.</param>
        /// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception>
        public void Remove(FeedEnclosure val)
        {
            List.Remove(val);
        }

        /// <summary>
        ///   Enumerator that can iterate through a FeedEnclosureCollection.
        /// </summary>
        /// <seealso cref='IEnumerator'/>
        /// <seealso cref='FeedEnclosureCollection'/>
        /// <seealso cref='FeedEnclosure'/>
        public class FeedEnclosureEnumerator : IEnumerator
        {
            IEnumerator baseEnumerator;
            IEnumerable temp;

            /// <summary>
            ///   Initializes a new instance of <see cref='FeedEnclosureEnumerator'/>.
            /// </summary>
            public FeedEnclosureEnumerator(FeedEnclosureCollection mappings)
            {
                this.temp = ((IEnumerable)(mappings));
                this.baseEnumerator = temp.GetEnumerator();
            }

            /// <summary>
            ///   Gets the current <see cref='FeedEnclosure'/> in the <seealso cref='FeedEnclosureCollection'/>.
            /// </summary>
            public FeedEnclosure Current
            {
                get
                {
                    return ((FeedEnclosure)(baseEnumerator.Current));
                }
            }

            object IEnumerator.Current
            {
                get
                {
                    return baseEnumerator.Current;
                }
            }

            /// <summary>
            ///   Advances the enumerator to the next <see cref='FeedEnclosure'/> of the <see cref='FeedEnclosureCollection'/>.
            /// </summary>
            public bool MoveNext()
            {
                return baseEnumerator.MoveNext();
            }

            /// <summary>
            ///   Sets the enumerator to its initial position, which is before the first element in the <see cref='FeedEnclosureCollection'/>.
            /// </summary>
            public void Reset()
            {
                baseEnumerator.Reset();
            }
        }
    }
}